package com.qidian.buy.product.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @date 2023/5/25 13:40
 */
@Configuration
public class RabbitMQConfig {

    // 配置扇形交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return  new FanoutExchange("item-add-exchange",true,true);
    };
    // 配置两个队列
    @Bean
    public Queue itemSearchQueue(){
        return new Queue("item-search-queue",true);
    }
    @Bean
    public Queue itemDetailQueue(){
        return new Queue("item-detail-queue",true);
    }
    // 把队列绑定到交换机上
    @Bean
    public Binding bindingItemSearch(){
        return BindingBuilder.bind(itemSearchQueue()).to(fanoutExchange());
    }
    @Bean
    public Binding bindingItemDetail(){
        return BindingBuilder.bind(itemDetailQueue()).to(fanoutExchange());
    }
}
